package org.jetlinks.community.standalone.configuration;

import org.jetlinks.community.standalone.unit.MoreUnit;
import org.jetlinks.core.metadata.unit.ValueUnit;
import org.jetlinks.core.metadata.unit.ValueUnitSupplier;
import org.jetlinks.core.metadata.unit.ValueUnits;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@Configuration
public class UnitConfiguration {

    @Autowired
    public void moreUnit() {
        ValueUnits.register(new ValueUnitSupplier() {
            @Override
            public Optional<ValueUnit> getById(String id) {
                return Optional.ofNullable(MoreUnit.of(id));
            }

            @Override
            public List<ValueUnit> getAll() {
                return Arrays.asList(MoreUnit.values());
            }
        });
    }
}
